using VSTalk.Engine.Core.XmppCommunication;
using VSTalk.Engine.Core.XmppCommunication.Services.Authorization;
using VSTalk.Model;

using agsXMPP.protocol.client;

namespace VSTalk.Engine.Core.XmppConnection.PresenceObserver
{
    public class AuthorizationPresenceHandler : IPresenceHandler
    {
        private Client _client;

        public AuthorizationPresenceHandler(Client client)
        {
            _client = client;
        }

        public bool IsApplicable(Presence presence)
        {
            return presence.Type == PresenceType.subscribe;
        }

        public void UpdateState(Presence presence)
        {
            var authorizationService = CommunicationServiceFactory.Create<AuthorizationProvider>(_client);
            authorizationService.HandleAuthorizationRequest(presence.From);
        }
    }
}